package com.admin.his.drugs.service.Impl;

import com.admin.his.common.dao.DrugsDao;
import com.admin.his.common.entity.DrugsEntity;
import com.admin.his.common.exception.ThisSystemException;
import com.admin.his.common.helper.StringHelperService;
import com.admin.his.drugs.ao.DrugsAddAo;
import com.admin.his.drugs.service.DrugsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DrugsServiceImpl implements DrugsService, StringHelperService {
    @Autowired
    private DrugsDao ddao;

    @Override
    public DrugsEntity addDrugs(DrugsAddAo ao) throws Exception {
        //清理参数
        String Manufacturer = trimAsNull(ao.getManufacturer());
        //业务逻辑
        if (ddao.selectExists("", ao.getDrugsCode())) {
            throw new ThisSystemException("DrugsCode.exists", "药品编号已存在");
        }
        //组装业务逻辑
        DrugsEntity dtt = new DrugsEntity();
        String Id = uuid();
        dtt.setID(Id);
        dtt.setDrugsCode(ao.getDrugsCode());
        dtt.setDrugsName(ao.getDrugsName());
        dtt.setDrugsUnit(ao.getDrugsUnit());
        dtt.setManufacturer(ao.getManufacturer());
        dtt.setDrugsDosageID(ao.getDrugsDosageID());
        dtt.setDrugsPrice(ao.getDrugsPrice());
        dtt.setMnemonicCode(ao.getMnemonicCode());
        dtt.setCreationDate(ao.getCreationDate());
        return dtt;
    }
}
